SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
CREATE DATABASE myNewDatabase
DROP DATABASE database_name , database_name
USE master
EXEC sp_dboption myOldData, 'Single User', TRUE
EXEC sp_renamedb 'myOldData', 'myNewData'
EXEC sp_dboption myNewData, 'Single User', FALSE
CREATE TABLE tablename (COLUMN_NAME column_type [(column_width[,column_precision])] .
CREATE TABLE tablename (fname     VARCHAR(20)   NOT NULL,lname     VARCHAR(30)   NOT NULL,hire_date SMALLDATETIME NULL,ssn       CHAR(11)      NOT NULL)
EXECUTE sp_help practice -- shows structure of table
ALTER TABLE XYZ ADD mi CHAR(1) NULL
SELECT * INTO tablename FROM tablename
SELECT * FROM tablename
IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'MyTableName' AND COLUMN_NAME = 'newcolumn') BEGIN ALTER TABLE MyTableName ADD newcolumn VARCHAR(32) NOT NULL DEFAULT '' END
IF EXISTS (SELECT * FROM dbo.syscolumns WHERE id = object_id(N'[dbo].[Projects]') AND NAME = 'ProjectManager') ALTER TABLE Projects DROP COLUMN [ProjectManager]
SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
INSERT INTO tablename (1996,'ford') -- INTO is an optional keyword in SQLServer
INSERT tablename VALUES ('a','b',DEFAULT,i) -- DEFAULT is a key word
INSERT INTO tablename VALUES(1001,'The Odyssey','Homer',NULL)
INSERT INTO TABLE (c17,c4,c8,c3)
EXECUTE sp_mystored_procedure1
INSERT INTO OtherDatabaseName.tablename
SELECT * FROM tablename WHERE loginid ='mfincher'
SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
UPDATE tablename SET col = VALUE|col|expr
UPDATE TABLE_NAME SET column_id = expr  WHERE condition
UPDATE tablename SET password = 'newpass' WHERE USER = 'quest'
UPDATE tablename SET password = 'newpass' WHERE (UserID > 1) AND (UserID < 113)
UPDATE tablename SET password = 'newpass', change='Y' WHERE USER = 'quest'
UPDATE tablename SET discount = discount + .1 WHERE lowqty >= 100
UPDATE tablename SET LNAME = UPPER(LNAME)
UPDATE tablename SET ytd_sales = (SELECT SUM(qty) FROM sales WHERE sales.title_id = titles.title_id AND ord_date BETWEEN '01/01/94' AND '12/31/94')
INSERT adult SELECT ju.member_no,  ad.street,  ad.city,  ad.state,  ad.zip, ad.phone_no, DATEADD(YY, 1, GETDATE()) FROM tablename ju JOIN tablename ad ON ju.adult_member_no = ad.member_no WHERE (DATEADD(YY, 18, ju.birth_date) < GETDATE())
DELETE FROM tablename WHERE userid < 50
DELETE tablename -- deletes all rows in a table (see "DROP TABLE" to delete a table)
TRUNCATE TABLE tablename -- deletes all rows, but doesn't log transaction
DELETE tablename WHERE title_id IN (SELECT title_id FROM ...)
SELECT str(myField, 12, 2) FROM tablename
SELECT CAST(datepart(yy,dtime) AS VARCHAR(4)) + ' ' + str(datepart(dy,dtime),3)  AS 'Year  Day', COUNT(TIME) AS 'Key Question Pages', AVG(TIME) AS 'avg time (msec)' FROM tablename WHERE NAME='Key' GROUP BY CAST(datepart(yy,dtime) AS VARCHAR(4)) + ' ' + str(datepart(dy,dtime),3) ORDER BY CAST(datepart(yy,dtime) AS VARCHAR(4)) + ' ' + str(datepart(dy,dtime),3) ASC
SELECT DISTINCT NAME FROM SYSDATABASES
SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
SELECT tablename.match_id AS match_id0, tablename.match_date AS match_date1, tablename.hometeam_goals AS hometeam_goals2, tablename.awayteam_goals AS awayteam_goals3, t1_.team_id AS team_id4, t1_.name AS name5, t1_.goals_given AS goals_given6, t1_.goals_taken AS goals_taken7, t1_.wins AS wins8, t1_.draws AS draws9, t1_.losses AS losses10, t2_.team_id AS team_id11, t2_.name AS name12, t2_.goals_given AS goals_given13, t2_.goals_taken AS goals_taken14, t2_.wins AS wins15, t2_.draws AS draws16, t2_.losses AS losses17, tablename.awayteam_id AS awayteam_id18, tablename.hometeam_id AS hometeam_id19  FROM `match` tablename INNER JOIN team t1_ ON tablename.hometeam_id = t1_.team_id INNER JOIN team t2_ ON tablename.awayteam_id = t2_.team_id
